package com.aaa.generics.demo01;

/**
 * @author C-Q
 * @version 1.1.0
 * @Description: 建立实例类设置属性在对象初始化时赋值相同的数据类型的数值
 * @date 2022/10/25
 */
public class Test01 {
    public static void main(String[] args) {
        //都是字符串类型
        Axis axis = new Axis("x","y");
        //整型
        Axis axis1 = new Axis(666,888);
        //浮点型
        Axis axis2 = new Axis(5.4,7.8);
        System.out.println(axis+"=======axis"+axis1+"=======axis1"+axis2+"=======axis2");
        //反例
        //初始化对象赋值时不满足两个类型都相同的条件，如果强转会出现类型转换异常
        //Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
        //	at com.aaa.generics.demo06.demo01.Test01.main(Test.java:21)
        Axis axis3 = new Axis(999,"字符串");
        String x = (String)axis3.getX();
        String y = (String)axis3.getY();
        System.out.println(axis3);
    }
}
